<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
export default {
  created() {
    this.loadVuex();
    if (this.$store.state.userInfo.token != undefined && this.$store.state.userInfo.token != null) {
      this.$http.defaults.headers.common["Authorization"] =
        "Bearer " + this.$store.state.userInfo.token;
    }
    if (document.location.href.indexOf("exam") == -1) {
      // 显示彩蛋
      this.easterEgg();
    }
  },
  methods: {
    // 加载存在session的vuex数据
    loadVuex() {
      //在页面加载时读取sessionStorage里的状态信息
      if (sessionStorage.getItem("store")) {
        this.$store.replaceState(
          Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem("store")))
        );
      }
      //在页面刷新时将vuex里的信息保存到sessionStorage里
      window.addEventListener("beforeunload", () => {
        sessionStorage.setItem("store", JSON.stringify(this.$store.state));
      });
    },
    // 彩蛋
    easterEgg() {
      this.$notify({
        title: "考研时间倒计时",
        dangerouslyUseHTMLString: true,
        message:
          "距离考研还有" +
          this.dateDifference() +
          "天&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n" +
          "bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>" +
          "<i style='float:right'>-来自王涛帅的精准计算</i>",
        duration: 5000,
        type: "success",
      });
    },
    // 计算时间差
    dateDifference() {
      var dateSpan, iDays;
      let sDate2 = "2021-12-26";
      const sDate1 = new Date();
      sDate2 = Date.parse(sDate2);
      dateSpan = sDate2 - sDate1;
      dateSpan = Math.abs(dateSpan);
      iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
      return iDays;
    },
  },
};
</script>
<style>
html,
body,
#app {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
::-webkit-scrollbar{
  width: 7px;
  height: 7px;
  background-color: #F5F5F5;
}

/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track {
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  background-color: #F5F5F5;
}

/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb{
  border-radius: 10px;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);
  background-color: #c8c8c8;
}
</style>
